import Vue from "vue";
import App from "./App.vue";
import Element from "element-ui";
import VueRouter from "vue-router";
import "element-ui/lib/theme-chalk/index.css";
import testPage from "./components/TestPage.vue";
import mainPage from "./components/mainPage.vue";
import hotPage from "./components/pages/hotPage.vue";
import historyPage from "./components/pages/historyPage";
import douBanPage from './components/pages/douBanPage'
import videoPage from './components/pages/videoPage'
import axios from 'axios'
import Vuex from 'vuex'

//引入elementui
Vue.prototype.$ELEMENT = { size: "small" };
Vue.prototype.$axios=axios
Vue.use(Element);
Vue.use(VueRouter)
Vue.use(Vuex)
Vue.config.productionTip = false;

// 配置状态管理
const store=new Vuex.Store({
  state:{
      domain:'https://www.zoratt.com',
      userInfo:{
        avatar:null,
        nickName:null,
        uid:null,
        portarit:null
      },
      searchTitle:'小猪佩奇',
      history:[]
  },
  mutations:{
    //更新用户信息
    userInfo(state, newUserInfo) {
      state.userInfo=newUserInfo
    },
    search(state,title){
      state.searchTitle=title
    },
    history(state,title){
      for(let i=0;i<state.history.length;i++){
        if(title==state.history[i])
          return
      }
      state.history=[...state.history,title]
      var res=''
      state.history.forEach((item)=>{
        res+=item+"//"
      })
      localStorage.setItem("data",res)
    },
    historyInit(state,arr){
      state.history=arr
    }
  }
})


const router = new VueRouter({
  routes: [
    { path: "/video", component: videoPage },
    { path: "/douban", component: douBanPage },
    { path: "/", component: mainPage },
    { path: "/index", component: mainPage },
    { path: "/history", component: historyPage },
    { path: "/test", component: testPage },
    { path: "/hot", component: hotPage },
  ],
});

new Vue({
  render: (h) => h(App),
  router,
  store
}).$mount("#app");
